import logging
import config
import os


def create_logger(name):
    logger = logging.getLogger(name)
    logger.setLevel(level=logging.INFO)
    log_path = os.path.join(config.APP_ROOT, 'logs')
    default_log_file = os.path.join(log_path, name + '.log')
    if not os.path.exists(default_log_file):
        os.system(r"touch {}".format(default_log_file))
    handler = logging.FileHandler(default_log_file)
    handler.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)

    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    console.setFormatter(formatter)

    logger.addHandler(handler)
    logger.addHandler(console)
    return logger

default_logger = create_logger('default')
singer_logger = create_logger('singer')
song_logger = create_logger('song')
song_url_logger = create_logger('song_url')
